#include <bits/stdc++.h>
using namespace std;
int main() {
  // multiset, priority_queue
  // priority_queue<int, vector<int>, greater<int>> pq;
  multiset<int> s;
  int n;
  cin >> n;
  while (n--) {
    int op, x;
    cin >> op;
    if (op == 1) {
      cin >> x;
      s.insert(x);
      // pq.push(x);
    } else if (op == 2) {
      cout << *s.begin() << endl;
    } else {
      // pq.pop();
      s.erase(s.begin());
    }
  }
}